let BASEURL = "https://vip.meerkat.top/webservice/";
import { urlencode , throwErr } from "./util.js";
// 请求的包装。。。
export default function request(mtd,URL,data){
	let method = "GET",
	header = {'content-type' : "application/json"};
	method = mtd.toUpperCase();//小写改为大写
	if(method=="POST"){
		header = {'content-type' : "application/x-www-form-urlencoded"};
	}else{
		header = {'content-type' : "application/json"};
		
	};
	if(data){
		if(method === "GET" || method === "DELETE"){
			URL = URL + "?" + urlencode(data);
		}
	};
	let p = new Promise((resolve,reject)=>{
		uni.request({
			url:BASEURL + URL,
			method:method,
			header:header,
			timeout:30000,
			success:function(res){
				var _data = res.data;
				if(_data && _data.code === 0){
					resolve(_data.data);
				}else{
					var text = throwErr(_data.code,res.data);
					reject({
						errMsg:text||res.data.msg
					});
				}
			},
			fail:function(e) {
				reject(e);
			}
		});
	});
	return p;
}